
var mongoose = require('mongoose');

var host = 'mongodb://localhost/aloka';

var DBAccess = function() {
    var instance;

    function init() {    
        return {
            connect: function(callback) {
                    if(arguments.length === 1 && arguments[0] == 'function') {
                        mongoose.connect(host);
                        callback();
                    }
                    else {
                        mongoose.connect(host);
                    }
            },
            disconnect: function() {
                mongoose.disconnect();
            },
            model: function(model) {
                return mongoose.model(model);
            }
        };
    }
    
    return {
        getInstance: function() {
            if(!instance) {
                instance = init();
            }
            return instance;
        }
    };
}();

module.exports = DBAccess;
